import { DataBlocker, DataProxy } from "../../frame/A-LIB/sources/lib.b.data";

class User {
	/** 设备ID */
	device_id: string;
	/** 国家信息 */
	country: string;
	/** 语言信息 */
	language: string;
	/** 用户ID */
	uid: number;
	/** 用户钻石 */
	diamond: number;

	/** 已领取的闯关任务记录 */
	task_round: string;
	/** 已领取的消除任务记录 */
	task_remove: string;
	/** 已完成的新手引导记录 */
	guide_record: string;
	/** 抽屉锁 */
	drawer_lock: boolean;

	/** 广告拦截 */
	adblock: boolean;
	gift: boolean;

	master: boolean;
	master_level: number;
	master_free_level: number;
	master_time: number;
	master_remove: number;

	free_diamond_reap: boolean;
}

const blocker: DataBlocker<User> = {
	get: {
		diamond(proxy, value) {
			return value ?? 0;
		},

		task_remove(proxy, value) {
			return value ?? '';
		},
		task_round(proxy, value) {
			return value ?? '';
		},
		guide_record(proxy, value) {
			return value ?? '';
		},
		drawer_lock(proxy, value) {
			return value ?? true;
		},

		adblock(proxy, value) {
			return value ?? true;
		},
		gift(proxy, value) {
			return value ?? true;
		},

		master(proxy, value) {
			return value ?? false;
		},
		master_level(proxy, value) {
			return value ?? 0;
		},
		master_free_level(proxy, value) {
			return value ?? 0;
		},
		master_remove(proxy, value) {
			return value ?? 0;
		},

		free_diamond_reap(proxy, value) {
			return value ?? false;
		},
	}
}

const proxy_map = new Map<string, User>();

export default function get_proxy(prefix?: string){
	prefix = prefix??'';
	if(!proxy_map.has(prefix)){
		proxy_map.set(prefix, DataProxy.initProxy('game_user', new User(), true, blocker, prefix));
	}
	return proxy_map.get(prefix);
}
